﻿using DataTransferBetweenViews.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace DataTransferBetweenViewsTest
{
    
    
    /// <summary>
    ///This is a test class for IModelTest and is intended
    ///to contain all IModelTest Unit Tests
    ///</summary>
    [TestClass()]
    public class IModelTest
    {
        private IList<string> favoriteBooks = new List<string>();     

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        internal virtual IModel CreateIModel()
        {
            // TODO: Instantiate an appropriate concrete class.
            IModel model = new Model();
            model.FavoriteBooksEvent += new EventHandler(this.GetBooks);
            return model;
        }

        /// <summary>
        ///A test for GetSubscribedPersons
        ///</summary>
        [TestMethod()]
        public void GetSubscribedPersonsTest()
        {
            IModel model = CreateIModel(); // TODO: Initialize to an appropriate value
            IList<string> expected = new List<string>(); // TODO: Initialize to an appropriate value
            expected.Add("Ravi");
            expected.Add("Surya");
            IList<string> actual;
            actual = model.GetSubscribedPersons();
            Assert.AreEqual(expected.Count, actual.Count);
            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for SelectedPerson
        ///</summary>
        [TestMethod()]
        public void SelectedPersonTest()
        {
            IModel model = CreateIModel(); // TODO: Initialize to an appropriate value
            string expected = string.Empty; // TODO: Initialize to an appropriate value
            model.SelectedPerson = expected;
            Assert.AreEqual(0, this.favoriteBooks.Count);
            model.SelectedPerson = "Ravi";
            Assert.AreEqual(2, this.favoriteBooks.Count);
            model.SelectedPerson = "Surya";
            Assert.AreEqual(3, this.favoriteBooks.Count);
        }

        /// <summary>
        /// Gets the books.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void GetBooks(object sender, EventArgs e)
        {
            if (sender != null)
            {
                this.favoriteBooks.Clear();
                foreach (string book in (IList<string>)sender)
                {
                    this.favoriteBooks.Add(book);
                }
            }
        }
    }
}
